var GridSetting = {
    url: $path_base + 'admin/adminUser/AjaxList',
    editurl: $path_base + "admin/adminUser/edit",
    exitsts : $path_base + "admin/adminUser/exists",
    validateurl : $path_base + "admin/adminUser/validator",
    colNames:['任务', '编号','用户名称','用户邮箱','用户角色','用户分组'],
    colModel:[
        {
            name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,search:false,
            formatter:'actions',
            formatoptions:{keys:true,delOptions:{recreateForm: true, beforeShowForm: MyGrid.beforeDeleteCallback}}
        },

        {name:'user_id',index:'user_id', key:true, width:60, sorttype:"int", editable: false},

        {
            name:'user_name',index:'user_name', width:150,editable: true,
            editoptions:{size:"20",maxlength:"50"},
            formoptions:{elmprefix:'<span style="color:red">*</span>'},
            editrules : {
                required: true,
                custom:true,
                custom_func:function(val,name, index)
                {
                    var data = { user_name : val , user_id : MyGrid.Instance.jqGrid('getGridParam', 'selrow')};
                    var url = GridSetting.exitsts;
                    return MyGrid.exists(url, data);
                }
            }
        },
        {
            name:'email',index:'email',width:150, sorttype:"int", editable: true,
            //edittype:"email",
            //editoptions:{size:"20",maxlength:"100"},
            formoptions:{elmprefix:'<span style="color:red">*</span>'},
            editrules : {
                required: true
            },
            edittype:"custom",
            editoptions:{
                custom_element : function(value, options) {
                    var el = document.createElement("input");
                    el.type="text";
                    el.value = value;
                    return el;
                },
                custom_value : function(elem, operation, value) {
                    if(operation === 'get') {
                        return $(elem).val();
                    } else if(operation === 'set') {
                        $('input',elem).val(value);
                    }
                }
            }
        },
        {
            name:'role_id',index:'role_id', width:60, sorttype:"int", editable: true,
            formoptions:{elmprefix:'<span style="color:red">*</span>'},
            editrules : {
                required: true
            },
            edittype:"select",
            editoptions:{
                dataUrl:$path_base + "admin/adminRole/AjaxListHelper",
                buildSelect: function(data) {
                    var response = jQuery.parseJSON(data);
                    var s = '<select>';
                    if (response && response.length) {
                        for (var i = 0, l=response.length; i<l ; i++) {
                            s += '<option value="'+response[i].role_id+'">'+response[i].role_name+'</option>';
                        }
                    }
                    return s + "</select>";
                }
            },
            formatter:function (cellvalue, options, rowObject)
            {
                return rowObject.user_role.role_name==undefined ? rowObject.role_id: rowObject.user_role.role_name;
            }
        },
        {
            name:'group_id',index:'group_id', width:60, sorttype:"int", editable: true,
            formoptions:{elmprefix:'<span style="color:red">*</span>'},
            editrules : {
                required: true
            },
            edittype:"select",
            editoptions:{
                dataUrl:$path_base + "admin/adminGroup/AjaxListHelper",
                buildSelect: function(data) {
                    var response = jQuery.parseJSON(data);
                    var s = '<select>';
                    if (response && response.length) {
                        for (var i = 0, l=response.length; i<l ; i++) {
                            s += '<option value="'+response[i].group_id+'">'+response[i].group_name+'</option>';
                        }
                    }
                    return s + "</select>";
                }
            },
            formatter:function (cellvalue, options, rowObject)
            {
                return rowObject.user_group.group_name==undefined ? rowObject.group_id: rowObject.user_group.group_name;
            }
        }
    ],
    prmNames: {
        id:"user_id"
    },
    jsonReader: {
        id: "user_id"
    }
};
MyGrid.createGrid(GridSetting);